<?php 
header("Content-type: text/html; charset=utf-8"); 
require_once('get_grade_curl.php');

include_once($_SERVER['DOCUMENT_ROOT']."/common/config.php");
$_conn = connect_mysql('wechat_grade');

$get = new get_data_curl();


if($_GET['xh'] && $_GET['xn'] && $_GET['xq']){
	$xh = $_GET['xh'];
	$xn = $_GET['xn'];
	$xq = $_GET['xq'];
	$sql = "SELECT * FROM wechat_user_secure WHERE studentid = '$xh'";
	$res = mysqli_query($_conn, $sql) or die;//(mysqli_error($_conn));
	$row = mysqli_fetch_array($res);
	
	if(!$row){
		$sql = "SELECT * FROM wechat_user_secure WHERE secureid = '$xh'";
		$res = mysqli_query($_conn, $sql) or die;//(mysqli_error($_conn));
		$row = mysqli_fetch_array($res);
		if($row)
			$xh = $row['studentid'];
		if(!$get->login('1203020333', 'zyb940708', '朱艺博')){
			if($get->get_error() == 'Failed to get random strings!'){
				$result = Array(
					'error' => '教务处挂了_(:3」∠)_',
				);
			}else{
				$result = Array(
					'error' => '登陆失败！',
				);
			}
			//echo $get->get_error();
		}else{
			$arr = array('qmcj', 'pscj', 'sycj', 'cj', 'kcmc', 'xkkh');
			$data = $get->get_any_data($arr, 'cjb', "xh = '$xh' AND xn = '$xn' AND xq = '$xq'");
			$name = $get->get_any_data(array('xm'), 'xsjbxxb', "xh = '$xh'");
			//$data = $get->get_grade_sql($xh);
			$result = Array(
				'error' => '',
				'grade' => $data,
				'name' => $name[0]
			);
		}
	}else{
		$result = Array(
			'error' => '',
			'grade' => Array(
				Array('_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_'),
				Array('_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_'),
				Array('_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_'),
				Array('_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_'),
				Array('_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_', '_(:3」∠)_')
			),
			'name' => '_(:3」∠)_'
		);
	}
}else{
	$result = Array(
		'error' => '信息不全！',
	);
}

$json = json_encode($result);
echo $json;

?>